package c.x.jy.service.service.impl;

import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.Query;
import c.x.jy.dao.dao.ClubDao;
import c.x.jy.dao.dto.ClubEntityDto;
import c.x.jy.dao.entity.ClubEntity;
import c.x.jy.service.service.ClubService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("clubService")
public class ClubServiceImpl extends ServiceImpl<ClubDao, ClubEntity> implements ClubService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        	QueryWrapper<ClubEntity> query= 	 new QueryWrapper<ClubEntity>() ;
    	if(params.get("searchKey")!=null&&params.get("searchValue")!=null&&!StringUtils.isEmpty(params.get("searchKey").toString())&&!StringUtils.isEmpty(params.get("searchValue").toString()))
    	    query.eq(  params.get("searchKey").toString(), params.get("searchValue"));
        if(params.get("businessId")!=null) 	query.eq("business_id", params.get("businessId"));
        if(params.get("recommend")!=null) 	query.eq("recommend", params.get("recommend"));
//        IPage<ClubEntity> page = this.page(
//                new Query<ClubEntity>().getPage(params),
//                 query
//        );

        IPage<ClubEntityDto> page = this.getBaseMapper().querypage(
                new Query<ClubEntity>().getPage(params),
                query
        );

        return new PageUtils(page);
    }

    @Override
    public ClubEntityDto getDtoById(Long id) {
        ClubEntityDto cd = this.getBaseMapper().getDtoById(id);
        return cd;
    }
}
